package top.yzhao.trackdatasystem.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import top.yzhao.trackdatasystem.form.TrackDataForm;
import top.yzhao.trackdatasystem.model.TrackData;

import java.util.List;

/**
 * User: zhaoyang
 * Date: 2020/3/13
 * Time: 1:01
 * Description:
 */
@Repository
@Mapper
public interface TrackDataDao {

    /**
     *  表固定GJHS-20180926-122744-(1319-848)，
     *  起始里860KM，
     *  长度为2KM(2000*4 = 8000)，
     *  结果list，service层再组合
     * @return
     */
    @Select("select " +
            "id,KM,Meters," +
            " `Lprf(mm)` as Lprf, `Rprf(mm)` as Rprf, `Laln(mm)` as Laln, " +
            " `Raln(mm)` as Raln, `Rage(mm)` as Gage, `Cant(mm)` as Cant, " +
            " `Xlvl(mm)` as Xlvl, `Wrap_1(mm)` as Wrap_1, `Cvtr(radpkm)` as Cvtr, " +
            " `Lacc_1(g)` as Lacc_1, `Vacc(g)` as Vacc, `LprfLW_3(mm)` as LprfLW_3, " +
            " `RprfLW_3(mm)` as RprfLW_3, `LalnLW_3(mm)` as LalnLW_3, `RalnLW_3(mm)` as RalnLW_3 " +
            " from `GJHS-20180926-122744-(1319-848)` where KM >= 860 and KM<= 861")
    public List<TrackData> getLeastTrackData();

    @Select("select count(*) from `GJHS-20180926-122744-(1319-848)` where KM >= 860 and KM<= 861")
    public int getTotalLeastTrackData();

    @Select("select " +
            "id,KM,Meters," +
            " `Lprf(mm)` as Lprf, `Rprf(mm)` as Rprf, `Laln(mm)` as Laln, " +
            " `Raln(mm)` as Raln, `Rage(mm)` as Gage, `Cant(mm)` as Cant, " +
            " `Xlvl(mm)` as Xlvl, `Wrap_1(mm)` as Wrap_1, `Cvtr(radpkm)` as Cvtr, " +
            " `Lacc_1(g)` as Lacc_1, `Vacc(g)` as Vacc, `LprfLW_3(mm)` as LprfLW_3, " +
            " `RprfLW_3(mm)` as RprfLW_3, `LalnLW_3(mm)` as LalnLW_3, `RalnLW_3(mm)` as RalnLW_3 " +
            " from `${tablename}` " +
            " WHERE 1000*KM+Meters >= ${1000*km+meters} AND 1000*KM+Meters <= ${1000*(km+1)+meters} " +
            " limit ${(currentPage-1)*pageSize},${pageSize}")
    public List<TrackData> getTrackData(TrackDataForm trackDataForm);

    @Select("select count(*) " +
            " from `${tablename}` " +
            " WHERE 1000*KM+Meters >= ${1000*km+meters} AND 1000*KM+Meters <= ${1000*(km+1)+meters} ")
    public int getTotalTrackData(TrackDataForm trackDataForm);

    @Select("select " +
            "id,KM,Meters," +
            " `Lprf(mm)` as Lprf, `Rprf(mm)` as Rprf, `Laln(mm)` as Laln, " +
            " `Raln(mm)` as Raln, `Rage(mm)` as Gage, `Cant(mm)` as Cant, " +
            " `Xlvl(mm)` as Xlvl, `Wrap_1(mm)` as Wrap_1, `Cvtr(radpkm)` as Cvtr, " +
            " `Lacc_1(g)` as Lacc_1, `Vacc(g)` as Vacc, `LprfLW_3(mm)` as LprfLW_3, " +
            " `RprfLW_3(mm)` as RprfLW_3, `LalnLW_3(mm)` as LalnLW_3, `RalnLW_3(mm)` as RalnLW_3 " +
            " from `${tablename}` " +
            " WHERE 1000*KM+Meters >= ${1000*km+meters} AND 1000*KM+Meters <= ${1000*(km+1)+meters} ")
        public List<TrackData> getTrackDataLine(TrackDataForm trackDataForm);
}
